package com.grass.p019lv.fragment;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.viewpager.widget.ViewPager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.APPLink;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.ClassifyBean;
import com.androidx.p013lv.base.bean.DeductTypeBean;
import com.androidx.p013lv.base.bean.SignInfo;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.listener.OnInventionScrollListener;
import com.androidx.p013lv.base.p015ui.AdapterInventionTab;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.TimeUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.invention.fragment.HomeLabelFragment;
import com.androidx.p013lv.invention.fragment.InventionTypeFragment;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.google.android.material.tabs.TabLayout;
import com.grass.p019lv.R;
import com.grass.p019lv.bean.ActivityBean;
import com.grass.p019lv.databinding.FragmentHomeBinding;
import com.grass.p019lv.dialog.DialogActivity;
import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;

/* renamed from: com.grass.lv.fragment.HomeFragment */
public class HomeFragment extends LazyFragment<FragmentHomeBinding> implements View.OnClickListener, OnInventionScrollListener {
    String HTTP_TAG = "classifyList";
    AdapterInventionTab adapter;
    private APPLink appLink;
    private ActivityBean bean;
    int classifyIdEd;
    List<LazyFragment> fragmentList;
    boolean isShowDeduct;
    CountDownTimer newTimes;
    List<ClassifyBean> strings;
    CountDownTimer timer;

    public void onClick(View view) {
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_home;
    }

    public static HomeFragment newInstance() {
        Bundle bundle = new Bundle();
        HomeFragment homeFragment = new HomeFragment();
        homeFragment.setArguments(bundle);
        return homeFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ((FragmentHomeBinding) this.binding).setClick(new OnClick());
        ((FragmentHomeBinding) this.binding).setStatus(0);
        this.isShowDeduct = false;
        List<ClassifyBean> classify = SpUtils.getInstance().getClassify();
        if (classify != null) {
            setViewPager(classify);
        } else {
            getInfo();
        }
    }

    @Override // com.androidx.p013lv.base.listener.OnInventionScrollListener
    public void onClassifyId(int i) {
        List<ClassifyBean> list = this.strings;
        if (list != null && list.size() > 0) {
            for (int i2 = 0; i2 < this.strings.size(); i2++) {
                if (i == this.strings.get(i2).getClassifyId()) {
                    ((FragmentHomeBinding) this.binding).viewPager.setCurrentItem(i2);
                    return;
                }
            }
        }
    }

    @Override // com.androidx.p013lv.base.listener.OnInventionScrollListener
    public void onScrolled(boolean z, final int i) {
        new Handler().postDelayed(new Runnable() {
            /* class com.grass.p019lv.fragment.HomeFragment.RunnableC29851 */

            public void run() {
                if (HomeFragment.this.binding == null || ((FragmentHomeBinding) HomeFragment.this.binding).toolbar == null || i != HomeFragment.this.classifyIdEd) {
                }
            }
        }, 100);
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (!NetUtil.isNetworkAvailable()) {
            ToastUtils.getInstance().showWeak("網路異常");
            return;
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().classifyList(), new HttpCallback<BaseRes<List<ClassifyBean>>>(this.HTTP_TAG) {
            /* class com.grass.p019lv.fragment.HomeFragment.C29862 */

            public void onLvSuccess(BaseRes<List<ClassifyBean>> baseRes) {
                if (baseRes.getData() == null || baseRes.getData().size() <= 0) {
                    ToastUtils.getInstance().showWeak("網路異常,請稍後再試");
                } else {
                    HomeFragment.this.setViewPager(baseRes.getData());
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void setViewPager(List<ClassifyBean> list) {
        this.fragmentList = new ArrayList();
        this.strings = list;
        for (int i = 0; i < this.strings.size(); i++) {
            ClassifyBean classifyBean = this.strings.get(i);
            if (classifyBean.getType() == 2) {
                this.fragmentList.add(HomeLabelFragment.newInstance(classifyBean.getClassifyId()));
            } else if (classifyBean.getType() == 3) {
                this.fragmentList.add(HomeLabelFragment.newInstance(classifyBean.getClassifyId()));
            } else {
                this.fragmentList.add(InventionTypeFragment.newInstance(classifyBean.getClassifyId(), this));
            }
            if (i == 0) {
                this.classifyIdEd = classifyBean.getClassifyId();
            }
        }
        this.adapter = new AdapterInventionTab(this.fragmentList, this.strings, getChildFragmentManager(), 1);
        ((FragmentHomeBinding) this.binding).viewPager.setAdapter(this.adapter);
        ((FragmentHomeBinding) this.binding).viewPager.setOffscreenPageLimit(4);
        ((FragmentHomeBinding) this.binding).viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            /* class com.grass.p019lv.fragment.HomeFragment.C29873 */

            @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
            public void onPageScrollStateChanged(int i) {
            }

            @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
            public void onPageSelected(int i) {
            }

            @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
            public void onPageScrolled(int i, float f, int i2) {
                if (i == 0) {
                    ((FragmentHomeBinding) HomeFragment.this.binding).setShow(0);
                    ((FragmentHomeBinding) HomeFragment.this.binding).ivActivity.setVisibility(View.VISIBLE);
                    return;
                }
                ((FragmentHomeBinding) HomeFragment.this.binding).ivActivity.setVisibility(View.GONE);
                ((FragmentHomeBinding) HomeFragment.this.binding).setShow(2);
            }
        });
        ((FragmentHomeBinding) this.binding).tabLayout.addOnTabSelectedListener((TabLayout.OnTabSelectedListener) new TabLayout.OnTabSelectedListener() {
            /* class com.grass.p019lv.fragment.HomeFragment.C29884 */

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabReselected(TabLayout.Tab tab) {
            }

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabSelected(TabLayout.Tab tab) {
                HomeFragment.this.changeTabTextView(tab, true);
                HomeFragment homeFragment = HomeFragment.this;
                homeFragment.classifyIdEd = homeFragment.strings.get(tab.getPosition()).getClassifyId();
            }

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabUnselected(TabLayout.Tab tab) {
                HomeFragment.this.changeTabTextView(tab, false);
            }
        });
        ((FragmentHomeBinding) this.binding).tabLayout.setupWithViewPager(((FragmentHomeBinding) this.binding).viewPager);
        if (((FragmentHomeBinding) this.binding).tabLayout.getTabCount() >= 2) {
            for (int i2 = 1; i2 < ((FragmentHomeBinding) this.binding).tabLayout.getTabCount(); i2++) {
                changeTabTextView(((FragmentHomeBinding) this.binding).tabLayout.getTabAt(i2), false);
            }
        }
    }

    public void getActivityInto() {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().getActivityInto(), "{}", new HttpCallback<BaseRes<List<ActivityBean>>>("getActivityInto") {
            /* class com.grass.p019lv.fragment.HomeFragment.C29895 */

            public void onLvSuccess(BaseRes<List<ActivityBean>> baseRes) {
                if (baseRes.getCode() == 200 && baseRes.getData() != null && baseRes.getData().size() > 0) {
                    HomeFragment.this.setActivityInto(baseRes.getData());
                }
            }
        });
    }

    public void getDeductData() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().deductType(), new HttpCallback<BaseRes<DeductTypeBean>>("getDeductData") {
            /* class com.grass.p019lv.fragment.HomeFragment.C29906 */

            public void onLvSuccess(BaseRes<DeductTypeBean> baseRes) {
                if (baseRes.getCode() == 200 && baseRes.getData() != null) {
                    final DeductTypeBean data = baseRes.getData();
                    HomeFragment.this.isShowDeduct = true;
                    ((FragmentHomeBinding) HomeFragment.this.binding).rlNewView.setVisibility(View.VISIBLE);
                    if (!TextUtils.isEmpty(data.getCoverPicture())) {
                        RequestManager with = Glide.with(((FragmentHomeBinding) HomeFragment.this.binding).f1956a.getContext());
                        with.load(SpUtils.getInstance().getString("domain") + data.getCoverPicture()).into(((FragmentHomeBinding) HomeFragment.this.binding).f1956a);
                    } else {
                        ((FragmentHomeBinding) HomeFragment.this.binding).f1956a.setBackgroundResource(R.drawable.bg_new_people_event);
                    }
                    ((FragmentHomeBinding) HomeFragment.this.binding).rlNewView.setOnClickListener(new View.OnClickListener() {
                        /* class com.grass.p019lv.fragment.HomeFragment.C29906.View$OnClickListenerC29911 */

                        public void onClick(View view) {
                            if (data.getJumpType() == 2) {
                                try {
                                    Intent intent = new Intent();
                                    intent.setAction("android.intent.action.VIEW");
                                    intent.setData(Uri.parse(data.getActUrl()));
                                    HomeFragment.this.startActivity(intent);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                new APPLink(HomeFragment.this.getContext()).urlLink(data.getActUrl());
                            }
                        }
                    });
                    HomeFragment.this.setNewPeopleTime(data.getCountDown());
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setNewPeopleTime(long j) {
        CountDownTimer r6 = new CountDownTimer(j, 1000) {
            /* class com.grass.p019lv.fragment.HomeFragment.CountDownTimerC29927 */

            public void onTick(long j) {
                if (HomeFragment.this.binding != null && ((FragmentHomeBinding) HomeFragment.this.binding).tvTimes != null) {
                    ((FragmentHomeBinding) HomeFragment.this.binding).tvTimes.setText(TimeUtils.stringForTime(j));
                }
            }

            public void onFinish() {
                ((FragmentHomeBinding) HomeFragment.this.binding).rlNewView.setVisibility(View.GONE);
                if (HomeFragment.this.newTimes != null) {
                    HomeFragment.this.newTimes.cancel();
                    HomeFragment.this.newTimes = null;
                }
            }
        };
        this.newTimes = r6;
        r6.start();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setActivityInto(List<ActivityBean> list) {
        this.bean = list.get(0);
        DialogActivity dialogActivity = new DialogActivity(getActivity(), this.bean);
        dialogActivity.setOnDismissListener(new DialogInterface.OnDismissListener() {
            /* class com.grass.p019lv.fragment.HomeFragment.DialogInterface$OnDismissListenerC29938 */

            public void onDismiss(DialogInterface dialogInterface) {
                ((FragmentHomeBinding) HomeFragment.this.binding).setActiveUrl(HomeFragment.this.bean.getCoverPicture());
                ((FragmentHomeBinding) HomeFragment.this.binding).setStatus(1);
                if (HomeFragment.this.isShowDeduct) {
                    ((FragmentHomeBinding) HomeFragment.this.binding).rlNewView.setVisibility(View.VISIBLE);
                }
            }
        });
        dialogActivity.show();
    }

    public void changeTabTextView(TabLayout.Tab tab, boolean z) {
        if (tab.getCustomView() == null) {
            tab.setCustomView(R.layout.tab_layout_text_invention);
        }
        TextView textView = (TextView) tab.getCustomView().findViewById(R.id.text1);
        if (z) {
            textView.setPadding(0, 0, 0, UiUtils.dp2px(5));
            textView.setTextAppearance(getContext(), R.style.TabLayoutBoldInventionTextSize);
            return;
        }
        textView.setPadding(0, 0, 0, UiUtils.dp2px(5));
        textView.setTextAppearance(getContext(), R.style.TabLayoutNormalInventionTextSize);
    }

    public static void setActiveImage(ImageView imageView, String str) {
        GlideUtils.loadVideo(SpUtils.getInstance().getString("domain") + str, imageView);
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment, com.gyf.immersionbar.components.ImmersionOwner
    public void initImmersionBar() {
        ImmersionBar.with(this).statusBarDarkFont(false).titleBar(((FragmentHomeBinding) this.binding).toolbar).init();
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag(this.HTTP_TAG);
        HttpUtils.getInsatance().cancelTag("getActivityInto");
        HttpUtils.getInsatance().cancelTag("getDeductData");
        CountDownTimer countDownTimer = this.newTimes;
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
    }

    /* access modifiers changed from: package-private */
    public void getSignInfo() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getSignUrl(), new HttpCallback<BaseRes<SignInfo>>("getSignUrl") {
            /* class com.grass.p019lv.fragment.HomeFragment.C29949 */

            public void onLvSuccess(BaseRes<SignInfo> baseRes) {
                if (200 != baseRes.getCode()) {
                    ToastUtils.getInstance().showSigh(baseRes.getMsg());
                } else if (!TextUtils.isEmpty(baseRes.getData().getSignUrl())) {
                    if (HomeFragment.this.appLink == null) {
                        HomeFragment homeFragment = HomeFragment.this;
                        homeFragment.appLink = new APPLink(homeFragment.getActivity());
                    }
                    HomeFragment.this.appLink.urlLink(baseRes.getData().getSignUrl());
                }
            }
        });
    }

    /* renamed from: com.grass.lv.fragment.HomeFragment$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void searchClick() {
            if (!HomeFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.SEARCH_ACTIVITY).navigation();
            }
        }

        public void downLoadClick() {
            if (!HomeFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.MINE_DOWNLOAD_VIDEO_ACTIVITY).navigation();
            }
        }

        public void historyClick() {
            if (!HomeFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.MINE_HISTORY_VIDEO_ACTIVITY).navigation();
            }
        }

        public void goToSign() {
            if (!HomeFragment.this.isOnClick()) {
                HomeFragment.this.getSignInfo();
            }
        }

        public void activeClick() {
            if (HomeFragment.this.bean == null || HomeFragment.this.isOnClick()) {
                return;
            }
            if (HomeFragment.this.bean.getJumpType() == 2) {
                try {
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.VIEW");
                    intent.setData(Uri.parse(HomeFragment.this.bean.getActUrl()));
                    HomeFragment.this.startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                if (HomeFragment.this.appLink == null) {
                    HomeFragment homeFragment = HomeFragment.this;
                    homeFragment.appLink = new APPLink(homeFragment.getContext());
                }
                HomeFragment.this.appLink.urlLink(HomeFragment.this.bean.getActUrl());
            }
        }
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onPause() {
        super.onPause();
        HttpUtils.getInsatance().cancelTag("getSignUrl");
    }
}
